package com.zx.cashiersystem.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by syh on 2016/7/1.
 */
public class Contants {
    private static final String TAG = "Contants";
    //网络请求码只是同一页面，多个请求，为了接受结果，判断是哪个
    public static final int LOGIN_CODE = 1;//登录的请求码
    public static final int ALIPAY_FACEPAY_CODE = 01;//支付宝当面付条码支付的请求码
    public static final int ALIPAY_QRPAY_CODE = 02;//支付宝当面付扫码支付的请求码
    public static final int WXPAY_CODE = 03;//微信条码支付的请求码
    public static final int WXQRPAY_CODE = 04;//微信扫码支付的请求
    public static final int QRCODE_WIDTH = 300;//生成的二维码的宽
    public static final int QRCODE_HEIGTH = 300;//生成的二维码的高


    private static final String SERVER_ADDRESS = "http://139.199.181.119/apizx/public/api/v1.";


    public static final String VERSION_UPDARE=SERVER_ADDRESS+"Versions/checkUpdate";
    //登录
    public static final String LOGIN = SERVER_ADDRESS + "Staffs/login";
    //获取菜品分类
    public static final String GET_MENU_TYPE = SERVER_ADDRESS + "Goods/getMenuType";
    //获取菜品信息
    public static final String GET_MENU = SERVER_ADDRESS + "Goods/getMenu";
    //获取订单列表
    public static final String GET_ORDER_LIST = SERVER_ADDRESS + "Orders/getOrder";
    //获取区域列表
    public static final String GET_TABLE_AREA = SERVER_ADDRESS + "Tables/getArea";
    //获取对应区域桌号列表
    public static final String GET_TABLE_LSIT = SERVER_ADDRESS + "Tables/getTable";
    //获取订单信息
    public static final String GET_ORDER_INFO = SERVER_ADDRESS + "";
    //查询会员
    public static final String SEARCH_VIP = SERVER_ADDRESS + "Users/getVipInfo";
    //查询会员
    public static final String ADD_VIP = SERVER_ADDRESS + "Users/addVip";



    //支付--为测试地址
    private static final String SERVER_ADDRESS_TEST = "http://192.168.0.66/";
    //支付宝条码支付
    public static final String ALIPAY_FACEPAY = SERVER_ADDRESS_TEST + "index.php/api/facepay/pay";
    //支付宝扫码支付
    public static final String ALIPAY_QRPAY = SERVER_ADDRESS_TEST + "index.php/api/qrpay/pay";
    //微信刷卡支付
    public static final String WXPAY = SERVER_ADDRESS_TEST + "index.php/api/weixinpay/pay";
    //微信扫码支付
    public static final String WXQRPAY = SERVER_ADDRESS_TEST + "index.php/api/wxnativepay/pay";


    /**
     * 判断是不是图
     *
     * @param str
     * @return
     */
    public static boolean isPic(String str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        if (str.toLowerCase().indexOf(".jpg") > 0 || str.toLowerCase().indexOf(".jpeg") > 0 || str.toLowerCase().indexOf(".png") > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 获取资源中的大小
     *
     * @param context
     * @param id
     * @return
     */
    public static int getDimen(Context context, int id) {
        return (int) context.getResources().getDimension(id);
    }

    public static int getColor(Context context, int id) {
        return context.getResources().getColor(id);
    }

    public static Drawable getDrawable(Context context, int id) {
        return context.getResources().getDrawable(id);
    }

    /**
     * 获取资源文件中string
     *
     * @param context
     * @param id
     * @return
     */
    public static String getString(Context context, int id) {
        String s = context.getResources().getString(id);
        return s;
    }

    /**
     * @param str
     * @return
     */
    public static String getName(String str) {
        String name = "";
        if (str.indexOf(" ") > 0) {
            name = str.substring(str.indexOf(" ") + 1);
        }
        return name;
    }

    public static String getFirst(String str) {
        return str.substring(0, 1);
    }

    /**
     * 判断手机号是否正
     *
     * @param mobiles
     * @return
     */
    public static boolean isMobileNO(String mobiles) {
        String telRegex = "[1][345789]\\d{9}";//"[1]"代表�位为数��[358]"代表第二位可以为3��中的一个，"\\d{9}"代表后面是可以是0�的数字，�位�
        if (TextUtils.isEmpty(mobiles)) return false;
        else return mobiles.matches(telRegex);
    }

    /**
     * 判断是否为空
     *
     * @param s
     * @return
     */
    public static boolean isEmpty(String s) {

        if (s == null || s.trim().length() == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static String formatDouble(String str){
        Double d = Double.parseDouble(str);
        return new DecimalFormat("###,##0.00").format(d);
    }

    /**
     * 验证邮箱
     *
     * @param email
     * @return
     */
    public static boolean isEmail(String email) {
        if (!email.matches("[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+")) {
            // logger.error("邮箱：email+"）校验未通过，格式不对);
            return false;
        }
        return true;
    }

    /**
     * 分割字符串为List
     *
     * @param str
     * @return
     */
    public static List<Integer> getArrayString(String str) {

        String[] strings = str.split("-");

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < strings.length; i++) {
            list.add(Integer.parseInt(strings[i]));
        }
        return list;
    }

    /**
     * 分割字符串为List
     *
     * @param str
     * @return
     */
    public static List<Integer> getArrayStrings(String str, String flag) {

        String[] strings = str.split(flag);

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < strings.length; i++) {
            list.add(Integer.parseInt(strings[i]));
        }
        return list;
    }

    //2016-11-12 13:49:09
    public static int[] getMonth_Day(String str) {
        return new int[]{Integer.parseInt(str.substring(0, 4)), Integer.parseInt(str.substring(5, 7)), Integer.parseInt(str.substring(8, 10))};
    }

    public static int compare_date(String start, String end) {
        java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Calendar c1 = java.util.Calendar.getInstance();
        java.util.Calendar c2 = java.util.Calendar.getInstance();

        String s1 = start + " 00:00:00";
        String s2 = end + " 00:00:00";
        if (isEmpty(end)) {
            s2 = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date()) + " 00:00:00";
        }

        try {
            c1.setTime(df.parse(s1));
            c2.setTime(df.parse(s2));
        } catch (java.text.ParseException e) {
            System.err.println("格式不正确");
        }
        int result = c1.compareTo(c2);
        if (result == 0)
            return 0;
        else if (result < 0)
            return 1;
        else
            return -1;
    }

    public static int compare_time(String start, String end) {
        String s1 = "2016-01-01 " + start + ":00";
        String s2 = "2016-01-01 " + end + ":00";
        java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Calendar c1 = java.util.Calendar.getInstance();
        java.util.Calendar c2 = java.util.Calendar.getInstance();
        try {
            c1.setTime(df.parse(s1));
            c2.setTime(df.parse(s2));
        } catch (java.text.ParseException e) {
            System.err.println("格式不正确");
        }
        int result = c1.compareTo(c2);
        if (result == 0)
            return 0;
        else if (result < 0)
            return 1;
        else
            return -1;
    }
}
